<?php


namespace App\Api\Models;

use Illuminate\Database\Eloquent\Model;

class CmcAfterSales extends Model
{
    protected $table='cmc_after_sales';
    //获取售后
    static public function getSales($gid,$uid)
    {
        return CmcAfterSales::where('goods_id',$gid)->where('uid',$uid)->get()->toArray();
    }

    //
    static public function getAfterTales($allowFiled,$uid,$orderId,$orderType)
    {
       return self::select($allowFiled)->where(['status'=>2,
                                                'uid'=>$uid,
                                                'order_id'=>$orderId,
                                                'order_type'=>$orderType])->first();
    }

    /**
     * 列表
     * @param $order_id
     * @param $order_type
     * @return mixed
     */
    static public function getSiteData($orderId,$orderType)
    {
        switch($orderType){
            case 3:
                //获取商品id
                $goodsId = SeckillOrder::join('cmc_store_seckill','cmc_store_seckill.id','=','cmc_seckill_orders.seckill_id')
                                        ->select('goods_id')
                                        ->where('cmc_store_seckill.id',$orderId)
                                        ->first()
                                        ->toArray();

                //获取店铺id
                $siteId = Goods::where('goods_id',$goodsId)->select('site_id')->first()->toArray();

                //查询店铺信息
                return CmcGoodsSite::where('site_id',$siteId)->get()->toArray();

            case 2:
                //获取商品id
                $goodsId = CmcPromotionPintuanOrder::join('cmc_promotion_pintuan','cmc_promotion_pintuan_order.pintuan_id','=','cmc_promotion_pintuan.pintuan_id')
                                                    ->select('goods_id')
                                                    ->where('id',$orderId)
                                                    ->first()
                                                    ->toArray();

                //获取店铺id
                $siteId = Goods::where('goods_id',$goodsId)->select('site_id')->first()->toArray();

                //查询店铺信息
                return CmcGoodsSite::where('site_id',$siteId)->get()->toArray();

            case 1:
                //获取商品id
                $goodsId = PromotionBargainLaunch::join('cmc_promotion_bargain_goods','cmc_promotion_bargain_launch.bargain_id','=','cmc_promotion_bargain_goods.bargain_id')
                                                ->select('cmc_promotion_bargain_launch.goods_id')
                                                ->where('launch_id',$orderId)
                                                ->first()
                                                ->toArray();

                //获取店铺id
                $siteId = Goods::where('goods_id',$goodsId)->select('site_id')->first()->toArray();

                //查询店铺信息
                return CmcGoodsSite::where('site_id',$siteId)->get()->toArray();
        }
    }

    /**
     * 撤销售后修改
     * @param $uid 用户id
     * @param $order_id 订单id
     * @param $order_type 订单类型
     * @return mixed
     */
    static public function updSiteData($uid,$orderId,$orderType)
    {
        return self::where('uid',$uid)
                   ->where('order_type',$orderType)
                   ->where('order_id',$orderId)
                   ->where('status',2)
                   ->update(['status'=>3]);
    }

    //订单号提交接口
    static public function creSiteData($uid,$orderId,$data,$orderType)
    {
       return self::where('uid',$uid)
                  ->where('order_id',$orderId)
                  ->where('order_type',$orderType)
                  ->where('status',3)
                  ->update([
                      'courier_number'=>$data['courier_number'],
                      'return_message'=>$data['return_message'],
                      'courier_price'=>$data['courier_price'],
                     'courier_image'=>$data['courier_image']
                  ]);
    }
}